package org.andes.kownledge.operator;

import org.andes.base.Bindings;
import org.andes.base.auxiliary;
import org.andes.kownledge.operator.func.Evaluatable;

public class Variable extends Term {
	private String name;
	public String getName() {
		return name;
	}
	public Variable(String name){
		if(name.substring(0,1).equals("?"))
			this.name=name.substring(1);
		else
			this.name=name;
	}
	public void setName(String name){
		this.name=name;
		
	}
	public String toString(){
		return "?"+name;
	}
	@Override
	public Term substBindings(Bindings bindings) {
		if(bindings.get_binding(this)!=null)
			return (Term) bindings.get_binding(this);
		else
			return new Variable(name);
	}
	public int hashCode()
    {
	    return name.hashCode()+100;
	}
	public boolean equals(Object o){
		if(o instanceof Variable)
			return toString().equals(((Variable)o).toString());
		else 
			return false;
	}
	@Override
	public Term renameVariable() {

		String name=getName()+auxiliary.makeNum();
		Variable var2=new Variable(name);
		return var2;
	}

}
